package com.share.example.selenium.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.example.selenium.mapper.OperateLogMapper;
import com.share.example.selenium.model.db.OperateLog;
import com.share.example.selenium.service.IBaseConfService;
import com.share.example.selenium.service.IOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * jenkins接口配置变  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-09-28
 */
@Service
public class OperateLogServiceImpl extends ServiceImpl<OperateLogMapper, OperateLog> implements IOperateLogService {
    @Autowired
    private OperateLogMapper operateLogMapper;

    @Autowired
    private IBaseConfService baseConfService;

    //返回id
    @Override
    public Long insertLog(String bizCode, String title, String status, String errMsg, String otherMsg, Date createTime, String handleId) {
        OperateLog record = new OperateLog();
        record.setTitle(title);
        record.setStatus(status);
        record.setBizCode(bizCode);
        record.setCreateTime(createTime);
        record.setErrMsg(errMsg);
        record.setOtherMsg(otherMsg);
        record.setHandleId(handleId);
        record.setUserId(baseConfService.getUserCode());
        int insert = operateLogMapper.insert(record);
        if (insert > 0) {
            return record.getId();
        } else {
            return null;
        }
    }

    @Override
    public int updateLogById(String status, String errMsg, String otherMsg, Date updateTime, Long id, String handleId) {
        OperateLog record = new OperateLog();
        record.setId(id);
        record.setStatus(status);
        record.setErrMsg(errMsg);
        record.setUpdateTime(updateTime);
        record.setOtherMsg(otherMsg);
        record.setHandleId(handleId);
        return operateLogMapper.updateById(record);
    }
}
